function TimeFormat(textObj, theTextValue){
    try {
	var textVal=textObj.value;
	if(textVal!=""){
			var count=0;
			var textVal=textObj.value;
			for(var i=0;i<textVal.length;i++){
				if(textVal.substr(i,1)==":") count++;
			}
			var strHour="",strMinute=""
			if(count==0){
				if(textVal.length <4) {
					goErrorTime(textObj);
					return;
				}
				strHour = textVal.substr(0,2);
				strMinute = textVal.substr(2,2);
			} else if(count==1){
				timeArray = textVal.split(":");
				strHour = timeArray[0];
				strMinute = timeArray[1];
			}
			else {
				// in case "/"
			}
			if(strHour.length<2) strHour = "0"+strHour;
			if(strMinute.length<2) strMinute = "0"+strMinute;
			// Reformat the time for validation
			if(strHour == 24) strHour = "00"
			var strSeperator = ":"
			var vTimeValueCheck = strHour + strSeperator + strMinute;
			if (!timeValid(vTimeValueCheck)) {
				goErrorTime(textObj);
				return;
			}

		textObj.value = strHour + ":" + strMinute;
		return true;
	}
      } catch(err) {
        throw new Error(" error in sub TimeFormat function() cause = " + err.message);
      } 
        
}
function timeValid(objName){
    try {
	var strHour;
	var strMinute;
	var datefield = objName;
	var strSeperator = ":"
	if (datefield.indexOf(strSeperator) != -1) {
		strTimeArray = datefield.split(strSeperator);
		if (strTimeArray.length != 2) {
			err = 1;
			return false;
		}
		else {
			strHour = strTimeArray[0];
			strMinute = strTimeArray[1];
		}
		if (isNaN(strHour)) return false;
		if (isNaN(strMinute)) return false;
		//alert(isNaN(strHour) + "..." + isNaN(strMinute))
		intHour = parseInt(strHour);
		intMinute = parseInt(strMinute);
		//alert(intHour + "..." + intMinute)
		//alert(isNaN(intHour) + "..." + isNaN(intMinute))
		if (isNaN(intHour)) {
			err = 2;
			return false;
		}
		if (isNaN(intMinute)) {
			err = 3;
			return false;
		}
		if(intHour > 24) return false;
		if(intMinute >= 60) return false;
		
		return true;
	}
    } catch(err) {
        throw new Error(" error in sub timeValid function() cause = " + err.message);
     } 

}
function DateFormat(textObj, theTextValue, e, dateCheck, dateType){
    try {
        var valDate=textObj.value;
        if(valDate!=""){
            if((dateCheck)){
                var count=0;
                var size = valDate.length;
                for(var i=0;i<size;i++){
                    if(valDate.substr(i,1)=="/") count++;
                }
                var strDay="",strMonth="",strYear="";
                if(count==0){
                    strDay = valDate.substr(0,2);
                    strMonth = valDate.substr(2,2);
                    strYear = valDate.substr(4,4);
                } else if(count==2){
                    dateArray = valDate.split("/");
                    strDay = dateArray[0];
                    strMonth = dateArray[1];
                    strYear = dateArray[2];
                }
                else {
                    // in case "/"
                }
                if(strDay.length<2) strDay = "0"+strDay;
                if(strMonth.length<2) strMonth = "0"+strMonth;
                if((strYear.length<4) || (strYear.length>4)){
                    goError(textObj);
                    return;
                }else if(parseInt(strYear) > 2643 || parseInt(strYear) < 1900){
                    textObj.value = '';
                    textObj.focus();
                    return;
                }else if(parseInt(strYear) > 2100){
                //---- check year by suree ---------------
                    strYear = parseInt(strYear) - 543;
                }
                // Reformat the date for validation
                var strSeperator = "/"
                var vDateValueCheck = strMonth+strSeperator+strDay+strSeperator+strYear;
                if (!dateValid(vDateValueCheck)) {
                    goError(textObj);
                    return;
                }
                textObj.value = strDay + "/" + strMonth + "/" + strYear;
                return true;
            }
        }
    } catch(err) {
        throw new Error(" error in sub DateFormat function() cause = " + err.message);
    } 
}

function goErrorTime(textObj){
    try {
	if(confirm("Invalid Time!\n[HH:MM] is required\nDo your want to edit now?")){
		textObj.focus();
		textObj.select();
	}else{
		textObj.value="";
	}
    } catch(err) {
        throw new Error(" error in sub goErrorTime function() cause = " + err.message);
     } 
}
function goError(textObj){
    try {
	if(confirm("Invalid Date!\n[dd/mm/yyyy(A.D.)] is required\nDo your want to edit now?")){
		textObj.focus();
		textObj.select();
	}else{
		textObj.value="";
	}  
    } catch(err) {
        throw new Error(" error in sub goError function() cause = " + err.message);
     } 
        
}


//check dateValid
function dateValid(objName) {
    try {
            var strDate;
            var strDateArray;
            var strDay;
            var strMonth;
            var strYear;
            var intday;
            var intMonth;
            var intYear;
            var booFound = false;
            var datefield = objName;
            var strSeparatorArray = new Array("-"," ","/",".");
            var intElementNr;
            // var err = 0;
            var strMonthArray = new Array(12);
            strMonthArray[0] = "Jan";
            strMonthArray[1] = "Feb";
            strMonthArray[2] = "Mar";
            strMonthArray[3] = "Apr";
            strMonthArray[4] = "May";
            strMonthArray[5] = "Jun";
            strMonthArray[6] = "Jul";
            strMonthArray[7] = "Aug";
            strMonthArray[8] = "Sep";
            strMonthArray[9] = "Oct";
            strMonthArray[10] = "Nov";
            strMonthArray[11] = "Dec";
            //strDate = datefield.value;
            strDate = objName;
            if (strDate.length < 1) {
            return true;
            }
            for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
            if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
            strDateArray = strDate.split(strSeparatorArray[intElementNr]);
            if (strDateArray.length != 3) {
            err = 1;
            return false;
            }
            else {
            strDay = strDateArray[0];
            strMonth = strDateArray[1];
            strYear = strDateArray[2];
            }
            booFound = true;
               }
            }
            if (booFound == false) {
            if (strDate.length>5) {
            strDay = strDate.substr(0, 2);
            strMonth = strDate.substr(2, 2);
            strYear = strDate.substr(4);
               }
            }
            //Adjustment for short years entered
            if (strYear.length == 2) {
            strYear = '20' + strYear;
            }
            strTemp = strDay;
            strDay = strMonth;
            strMonth = strTemp;
            intday = parseInt(strDay, 10);
            if (isNaN(intday)) {
            err = 2;
            return false;
            }
            intMonth = parseInt(strMonth, 10);
            if (isNaN(intMonth)) {


            for (i = 0;i<12;i++) {
            if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
            intMonth = i+1;
            strMonth = strMonthArray[i];
            i = 12;
               }
            }
            if (isNaN(intMonth)) {
            err = 3;
            return false;
               }


            }
            intYear = parseInt(strYear, 10);
            if (isNaN(intYear)) {
            err = 4;
            return false;
            }
            if (intMonth>12 || intMonth<1) {
            err = 5;
            return false;
            }
            if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
            err = 6;
            return false;
            }
            if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
            err = 7;
            return false;
            }
            if (intMonth == 2) {
            if (intday < 1) {
            err = 8;
            return false;
            }
            if (LeapYear(intYear) == true) {
            if (intday > 29) {
            err = 9;
            return false;
               }
            }
            else {
            if (intday > 28) {
            err = 10;
            return false;
                  }
               }
            }
            return true;
        } catch(err) {
            throw new Error(" error in sub dateValid function() cause = " + err.message);
        } 
     }
    function LeapYear(intYear) {
        try {
            if (intYear % 100 == 0) {
                if (intYear % 400 == 0) {
                    return true;
                }
            }
            else {
                if ((intYear % 4) == 0) {
                    return true;
                }
            }
            return false;

        } catch(err) {
            throw new Error(" error in sub LeapYear function() cause = " + err.message);
        } 
    }

function ChangeDateFormat_TextBoxOnBlur(obj) {
    try {
	var value = obj.value;
	//alert(value.indexOf('/'));
	//alert(value.length);
	if(value.indexOf('/')==-1 && value.length>=8) {
		var str = value.substring(0,2) + '/' + value.substring(2,4) + '/' + value.substring(4,8);
		//alert(str);
		if(str.length==10) obj.value = str;
	}
      } catch(err) {
        throw new Error(" error in sub ChangeDateFormat function() cause = " + err.message);
      } 
}

function dateOnKeyPress()
{
      try {
            if ((window.event.keyCode < 47 || window.event.keyCode > 57 ) && window.event.keyCode != 47) //Not Numeric Key (47 is /)
                    window.event.returnValue=false;
       } catch(err) {
        throw new Error(" error in sub dateOnKeyPress function() cause = " + err.message);
      } 
}

function checkValid(startD,endD,formatDate,startLabel,endLabel){
    //alert(compareDate(startDate,endDate,formatDate));
    try {
        var startDate = startD.value;   
        var endDate = endD.value;   
        if(startDate == null || startDate == ''){
            return;
        }else if(endDate == null || endDate == ''){
            return;
        }else{
             if(compareDate(startDate,endDate,formatDate) != 1 ){
                alert('Please enter '+startLabel+' less than '+endLabel+'.');
                startD.value= '';
                endD.value= '';
                startD.focus();
            }
        }
     } catch(err) {
        throw new Error(" error in sub checkValid function() cause = " + err.message);
      } 
}
function checkValidEquals(startD,endD,formatDate,startLabel,endLabel){
    //alert(compareDate(startDate,endDate,formatDate));
    try {
        var startDate = startD.value;
        var endDate = endD.value;
        if(startDate == null || startDate == ''){
            return;
        }else if(endDate == null || endDate == ''){
            return;
        }else{
             if(compareCalendar(startDate,endDate,formatDate) == 1 ){
                alert('Please enter '+endLabel+' less than '+startLabel+'.');
                startD.value= '';
                endD.value= '';
                startD.focus();
            }
        }
     } catch(err) {
        throw new Error(" error in sub checkValidEquals function() cause = " + err.message);
     }
}


function compareDate(startDate,endDate,formatDate){
    try {
	if(formatDate=="MM/dd/yyyy"){
		var date1 = startDate.substring(3,5);
		var month1 = startDate.substring(0,2);
		var year1 = startDate.substring(6,10);
		var date2 = endDate.substring(3,5);
		var month2 = endDate.substring(0,2);
		var year2 = endDate.substring(6,10);
	}else{
		var date1 = startDate.substring(0,2);
		var month1 = startDate.substring(3,5);
		var year1 = startDate.substring(6,10);
		var date2 = endDate.substring(0,2);
		var month2 = endDate.substring(3,5);
		var year2 = endDate.substring(6,10);	
	}
						
	var t1 = Date.UTC(year1, parseFloat(month1)-1, date1);
	var t2 = Date.UTC(year2, parseFloat(month2)-1, date2);
			
	var diffDate = t1-t2;
		
	if(diffDate < 0) return 1;
	else if(diffDate > 0 || diffDate == 0) return -1;
	else return 0;
      } catch(err) {
        throw new Error(" error in sub compareDate function() cause = " + err.message);
      } 
}

function compareCalendar(startDate,endDate,formatDate){
    try {
	if(formatDate=="MM/dd/yyyy"){
		var date1 = startDate.substring(3,5);
		var month1 = startDate.substring(0,2);
		var year1 = startDate.substring(6,10);
		var date2 = endDate.substring(3,5);
		var month2 = endDate.substring(0,2);
		var year2 = endDate.substring(6,10);
	}else{
		var date1 = startDate.substring(0,2);
		var month1 = startDate.substring(3,5);
		var year1 = startDate.substring(6,10);
		var date2 = endDate.substring(0,2);
		var month2 = endDate.substring(3,5);
		var year2 = endDate.substring(6,10);	
	}
						
	var t1 = Date.UTC(year1, parseFloat(month1)-1, date1);
	var t2 = Date.UTC(year2, parseFloat(month2)-1, date2);
			
	var diffDate = t1-t2;

	if(diffDate < 0) return -1;
	else if(diffDate > 0) return 1;
	else if(diffDate == 0) return 0;
      } catch(err) {
        throw new Error(" error in sub compareCalendar function() cause = " + err.message);
      } 
}

function compareDateTime(startDate,endDate,formatDate){
    try {
	if(formatDate=="MM/dd/yyyy HH:mm:ss"){
		var date1 = startDate.substring(3,5);
		var month1 = startDate.substring(0,2);
		var year1 = startDate.substring(6,10);
		var hours1 = startDate.substring(11,13);
		var minutes1 = startDate.substring(14,16);
		var second1 = startDate.substring(17,19);		
		var date2 = endDate.substring(3,5);
		var month2 = endDate.substring(0,2);
		var year2 = endDate.substring(6,10);
		var hours2 = endDate.substring(11,13);
		var minutes2 = endDate.substring(14,16);
		var second2 = endDate.substring(17,19);
	}else{
		var date1 = startDate.substring(0,2);
		var month1 = startDate.substring(3,5);
		var year1 = startDate.substring(6,10);
		var hours1 = startDate.substring(11,13);
		var minutes1 = startDate.substring(14,16);
		var second1 = startDate.substring(17,19);		
		var date2 = endDate.substring(0,2);
		var month2 = endDate.substring(3,5);
		var year2 = endDate.substring(6,10);
		var year2 = endDate.substring(6,10);
		var hours2 = endDate.substring(11,13);
		var minutes2 = endDate.substring(14,16);
		var second2 = endDate.substring(17,19);			
	}
//	var t1 = Date.UTC(parseInt(year1), parseInt(month1)-1, parseInt(date1), parseInt(hours1), parseInt(minutes1), parseInt(second1));
//	var t2 = Date.UTC(parseInt(year2), parseInt(month2)-1, parseInt(date2), parseInt(hours2), parseInt(minutes2), parseInt(second2));
	var t1 = Date.UTC(year1, parseInt(month1,10)-1, date1, hours1, minutes1, second1);
	var t2 = Date.UTC(year2, parseInt(month2,10)-1, date2, hours2, minutes2, second2);
	var diffDate = t1-t2;
	if(diffDate < 0) return 1;
	else if(diffDate > 0) return -1;
	else if(diffDate == 0)return 0;
	else return 2;
       } catch(err) {
        throw new Error(" error in sub compareDateTime function() cause = " + err.message);
      } 
}

function compareDateTimeElement(year1, month1, date1, hours1, minutes1, second1, year2, month2, date2, hours2, minutes2, second2)
{
    try {
	var t1 = Date.UTC(parseInt(year1), parseInt(month1)-1, parseInt(date1), parseInt(hours1), parseInt(minutes1), parseInt(second1));
	var t2 = Date.UTC(parseInt(year2), parseInt(month2)-1, parseInt(date2), parseInt(hours2), parseInt(minutes2), parseInt(second2));
	var diffDate = t1-t2;
	if(diffDate < 0) return 1;
	else if(diffDate > 0) return -1;
	else if(diffDate == 0)return 0;
	else return 2;
       } catch(err) {
        throw new Error(" error in sub compareDateTimeElement function() cause = " + err.message);
      } 
}

function calulateBetweenDate(startDate,endDate,formatDate){
    try {
	if(formatDate=="MM/dd/yyyy HH:mm:ss"){
	
		var date1 = startDate.substring(3,5);
		var month1 = startDate.substring(0,2);
		var year1 = startDate.substring(6,10);
		var hours1 = startDate.substring(11,13);
		var minutes1 = startDate.substring(14,16);
		var second1 = startDate.substring(17,19);		
		var date2 = endDate.substring(3,5);
		var month2 = endDate.substring(0,2);
		var year2 = endDate.substring(6,10);
		var hours2 = endDate.substring(11,13);
		var minutes2 = endDate.substring(14,16);
		var second2 = endDate.substring(17,19);
	}else{

		var date1 = startDate.substring(0,2);
		var month1 = startDate.substring(3,5);
		var year1 = startDate.substring(6,10);
		var hours1 = startDate.substring(11,13);
		var minutes1 = startDate.substring(14,16);
		var second1 = startDate.substring(17,19);		
		var date2 = endDate.substring(0,2);
		var month2 = endDate.substring(3,5);
		var year2 = endDate.substring(6,10);
		var year2 = endDate.substring(6,10);
		var hours2 = endDate.substring(11,13);
		var minutes2 = endDate.substring(14,16);
		var second2 = endDate.substring(17,19);			
	}
		
	var t1 = Date.UTC(parseInt(year1), parseInt(month1)-1, parseInt(date1), parseInt(hours1), parseInt(minutes1), parseInt(second1));
	var t2 = Date.UTC(parseInt(year2), parseInt(month2)-1, parseInt(date2), parseInt(hours2), parseInt(minutes2), parseInt(second2));
	
	var diffDate = t2-t1;

	var minutes = 1000*60;
	var hours = minutes*60;
	var days = hours*24;
	
	var y = diffDate/days;
	
	return y;
      } catch(err) {
        throw new Error(" error in sub calulateBetweenDate function() cause = " + err.message);
      } 
}


function compareCurrentDateTime(dateTime, language, formatDate){
    try {
	if(formatDate=="MM/dd/yyyy HH:mm:ss"){
		var date = dateTime.substring(3,5);
		var month = dateTime.substring(0,2);
		var year = dateTime.substring(6,10);
		var hours = dateTime.substring(11,13);
		var minutes = dateTime.substring(14,16);
		var second = dateTime.substring(17,19);
	}else{
		var date = dateTime.substring(0,2);
		var month = dateTime.substring(3,5);
		var year = dateTime.substring(6,10);
		var hours = dateTime.substring(11,13);
		var minutes = dateTime.substring(14,16);
		var second = dateTime.substring(17,19);
	}	
	
	if(language == 'th_TH'){
		var t1 = new Date(year-543, month-1, date,hours, minutes, second);
	}else {
		var t1 = new Date(year, month-1, date,hours, minutes, second);
	}		
	var t2 = new Date();
	if(t1 > t2) return 1;
	else if(t1 < t2) return -1;
	else if(t1 == t2)return 0;
	else return 2;
      } catch(err) {
        throw new Error(" error in sub compareCurrentDateTime function() cause = " + err.message);
      } 
}

function checkWeekendDate(dateObj, formatDate){
    var startDate = dateObj.value;
    try {
	if(formatDate=="MM/dd/yyyy"){
            var date1 = startDate.substring(3,5);
            var month1 = startDate.substring(0,2);
            var year1 = startDate.substring(6,10);
		
	} else {
            var date1 = startDate.substring(0,2);
            var month1 = startDate.substring(3,5);
            var year1 = startDate.substring(6,10);
	}
        var t1 = new Date();
        var t =   Date.UTC(year1, parseFloat(month1) -1, date1);
        t1.setTime(t);
         if(t1.getDay() == 6) {
          
            if(!confirm("Invalid date! \n'" + startDate + "' is saturday \n" + "Do you want to edit now?" )) {;
                dateObj.value = "";
                
            }
            dateObj.focus();
            return;
            
        } else if(t1.getDay() == 0) {
  
            if(!confirm("Invalid date! \n " + startDate + " is sunday \n" + "Do you want to edit now?" )) {
                dateObj.value = "";
                
            }
            dateObj.focus();
            return;
        } 
    } catch(err) {
        throw new Error(" error in sub checkWeekendDate function() cause = " + err.message);
    } 
}
function checkHolidayDate(dateObj){
    if( dateObj.value != "undefined" &&  dateObj.value != null &&  dateObj.value != "") {
        getHorlidayDateTextData("HolidayText" , dateObj.value);
        if(dateFlag){
            if(!confirm("Invalid date! \n " + dateObj.value + " is holiday \n" + "Do you want to edit now?" )) {
                dateObj.value = "";
            }
            dateObj.focus();
            return;
        } 
        dateFlag = false;
    }
}
function isWeekendDate(startDate, formatDate, flgAlert){
    try {
        var isAlert = flgAlert==false?false:true;
	if(formatDate=="MM/dd/yyyy"){
            var date1 = startDate.substring(3,5);
            var month1 = startDate.substring(0,2);
            var year1 = startDate.substring(6,10);
		
	} else {
            var date1 = startDate.substring(0,2);
            var month1 = startDate.substring(3,5);
            var year1 = startDate.substring(6,10);
	}

        var t1 =  new Date(parseInt(year1), parseInt(month1, 10) -1, parseInt(date1, 10),0, 0, 0);

        if(t1.getDay() == 6) {
            if(isAlert){
                alert("Invalid date! \n " + startDate + " is weekend \n" + " System will auto gen next day." );
            }
            return true;  
        } else if(t1.getDay() == 0) {
            if(isAlert){
                alert("Invalid date! \n " + startDate + " is weekend \n" + " System will auto gen next day." );
            }
            return true;
        }
        return false;
    } catch(err) {
        throw new Error(" error in sub isWeekendDate function() cause = " + err.message);
    } 
}
function isHolidayDate(date, flgAlert){
    var isAlert = flgAlert==false?false:true;
    if( date != "undefined" &&  date != null &&  date != "") {
        getHorlidayDateTextData("HolidayText" , date);
        if(dateFlag){
            dateFlag = false;
            return true;
        } 
        dateFlag = false;
        return false;
    }
}
function compareCurrentDate(dateTime, formatDate){
    try {
	if(formatDate=="MM/dd/yyyy"){
            var date = dateTime.substring(3,5);
            var month = dateTime.substring(0,2);
            var year = dateTime.substring(6,10);
	}else{
            var date = dateTime.substring(0,2);
            var month = dateTime.substring(3,5);
            var year = dateTime.substring(6,10);
	}	
	
	var t1 = year + month + date;

	var nowDate     = new Date();
        var dateN       = ""+nowDate.getDate();
        var monthN      = ""+(nowDate.getMonth() + 1);
        var yearN       = ""+nowDate.getFullYear();

        dateN           = ( dateN.length == 2 ) ? dateN : "0" + dateN ;
        monthN          = ( monthN.length == 2 ) ? monthN : "0" + monthN ;
        yearN           = yearN;

        var t2          = yearN + monthN + dateN;

	if(t1 > t2) return 1;
	else if(t1 < t2) return -1;
	else if(t1 == t2)return 0;
	else return 2;
    } catch(err) {
        throw new Error(" error in sub compareCurrentDate function() cause = " + err.message);
    } 
}

function changeDateFormat(valDate){
    var count=0;
    var size = valDate.length;
    for(var i=0;i<size;i++){
        if(valDate.substr(i,1)=="/") count++;
    }
    var strDay="",strMonth="",strYear="";
    if(count==0){
        strDay = valDate.substr(0,2);
        strMonth = valDate.substr(2,2);
        strYear = valDate.substr(4,4);
    } else if(count==2){
        dateArray = valDate.split("/");
        strDay = dateArray[0];
        strMonth = dateArray[1];
        strYear = dateArray[2];
    }
    if(strDay.length<2) strDay = "0"+strDay;
    if(strMonth.length<2) strMonth = "0"+strMonth;
    if(parseInt(strYear) > 2100){
        strYear = parseInt(strYear) - 543;
    }
    // Reformat the date for validation
    var strSeperator = "/"
    var vDateValueCheck = strMonth+strSeperator+strDay+strSeperator+strYear;
    if (!dateValid(vDateValueCheck)) {
        return "";
    }
    return strDay + "/" + strMonth + "/" + strYear;
}

function checkValidTime(startT,endT,startLabel,endLabel){
    
    try {
        var startTime = startT.value;
        var endTime = endT.value;
        if(startTime == null || startTime == ''){
            return;
        }else if(endTime == null || endTime == ''){
            return;
        }else{
            if(startTime.charAt(2) == ":" && endTime.charAt(2) == ":"){
                if(compareTime(startTime,endTime) != 1 ){
                    alert('Please enter '+startLabel+' less than '+endLabel+'.');
                    startT.value= '';
                    endT.value= '';
                    startT.focus();
                }
            }else{
                alert("Invalid format Time!");
                startT.value= '';
                endT.value= '';
                startT.focus();
                return;
            }
        }
     } catch(err) {
        throw new Error(" error in sub checkValidTime function() cause = " + err.message);
      }
}

function compareTime(startTime,endTime){
    try {

        var hh = startTime.substring(0,2);
        var mm = startTime.substring(3,5);
        var hh2 = endTime.substring(0,2);
        var mm2 = endTime.substring(3,5);
	
	var t1 = Date.UTC(hh, mm);
	var t2 = Date.UTC(hh2, mm2);

	var diffTime = t1-t2;

	if(diffTime < 0) return 1;
	else if(diffTime > 0 || diffTime == 0) return -1;
	else return 0;
      } catch(err) {
        throw new Error(" error in sub compareDate function() cause = " + err.message);
      }
}

function dateAdd(p_Interval, p_Number, p_Date, formatDate){
    if(formatDate=="MM/dd/yyyy"){
        var date = p_Date.substring(3,5);
        var month = p_Date.substring(0,2);
        var year = p_Date.substring(6,10);
    }else{
        var date = p_Date.substring(0,2);
        var month = p_Date.substring(3,5);
        var year = p_Date.substring(6,10);
    }
    p_Number = new Number(p_Number);
    var dt = new Date(year, month, date);
    switch(p_Interval.toLowerCase()){
        case "yyyy": {// year
            dt.setFullYear(dt.getFullYear() + p_Number);
            break;
        }
        case "q": { // quarter
            dt.setMonth(dt.getMonth() + (p_Number*3));
            break;
        }
        case "m": { // month
            dt.setMonth(dt.getMonth() + p_Number);
            break;
        }
        case "y": // day of year
        case "d": // day
        case "w": { // weekday
            dt.setDate(dt.getDate() + p_Number);
            break;
        }
        case "ww": { // week of year
            dt.setDate(dt.getDate() + (p_Number*7));
            break;
        }
        case "h": { // hour
            dt.setHours(dt.getHours() + p_Number);
            break;
        }
        case "n": { // minute
            dt.setMinutes(dt.getMinutes() + p_Number);
            break;
        }
        case "s": { // second
            dt.setSeconds(dt.getSeconds() + p_Number);
            break;
        }
        case "ms": { // second
            dt.setMilliseconds(dt.getMilliseconds() + p_Number);
            break;
        }
        default: {
            return "invalid interval: '" + p_Interval + "'";
        }
    }
    return dt;
}
function genNextDay(date, dayAdd){
    if (!date) return "";
    if (date.length != 10 ) return "";

    var date = date.split("/");
    if ( date.length != 3 ) return "";

    var day     = date[0];
    var month   = date[1];
    var year    = parseInt(date[2]);
    var dayNo   = parseInt(dayAdd);

    day         = ( day.substr(0, 1) == "0" )?parseInt ( day.substr( 1, 1 )) : parseInt( day );
    month       = ( month.substr (0, 1) == "0" )?parseInt ( month.substr( 1, 1 )) - 1 : parseInt( month ) - 1;
    year        = ( year > 2400 )?( year-543 ):year;

    var objDate = new Date( year, month, day );
    day += dayNo;

    objDate.setDate( day );

    var tmpDate = objDate.getDate() + "/" + (objDate.getMonth() + 1) + "/" + objDate.getFullYear();
    var newDate = changeDateFormat(tmpDate);

    return newDate;
}